| Miles Sound System SDK 7.2a |
Q: | How do I use multi-channel sound output in Miles? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A: | Sound cards and integrated PC motherboard chipsets offering more than the usual two stereo output channels have been widely available for some time, primarily to support DVD surround playback. Game developers have used various '3D sound' solutions ranging from Dolby Surround processing to elaborate head-related transfer function implementations to give players a sense of simulated spatial orientation and distance, but only a few recent titles such as Half-Life 2 have offered the ability to render in-game sound effects and dialogue through the 5.1-channel or similar multichannel speaker systems that more and more users own. In MSS version 7.0, we've given you the ability to add true multispeaker digital audio support in an afternoon's worth of coding. What output formats are available? The DOS and Macintosh platforms support conventional mono/stereo output formats only. Xbox and Xbox 360 are even simpler to understand -- it's inherently a 5.1-channel system. For more information on audio support on the Xbox, see the Overview for Microsoft Xbox section . As usual, on platforms like Win32/Win64 and the Sony PS2/PS3, things get interesting. When you call AIL_open_digital_driver (or its quick API equivalent, AIL_quick_startup), you'll need to tell Miles what audio output format to use via the channels parameter. This is an integer parameter that was previously limited to values of either 1 or 2 for mono or stereo output. Beginning with MSS 7, you can also pass a value of the enum type MSS_MC_SPEC to functions that open a digital driver. A brief explanation of these options appears below.
When using the MSS_MC_USE_SYSTEM_CONFIG flag for the channels parameter, the output configuration is determined as follows (note that not all of the speaker systems are supported on all platforms):
You can query the chosen MSS_MC_SPEC value by calling AIL_speaker_configuration on the returned HDIGDRIVER. Unfortunately, the control-panel or other system setting may not reflect the user's actual hardware configuration. Worst, from the sound driver's point of view, the configuration may be determined by a separate, proprietary applet -- which may or may not keep itself synchronized with the operating system settings. Further, the limited range of operating system values don't begin to address all of the possible configurations (for example, under Windows there is no option for 6.1 speakers). Therefore, it's best not to rely solely on the OS to report a meaningful speaker-configuration value; we strongly recommend offering the user the ability to select an MSS_MC_ configuration directly as part of your application's sound-options dialog. So, default to MSS_MS_USE_SYSTEM_CONFIG, but give the user the ability to override. Understanding the DirectSound3D alternatives on Windows On the sound card hardware, DirectSound 3D can do many of the functions that Miles provides in its software mixer. In theory, hardware mixing saves CPU time. In reality, the advantage ranges from subtle to unmeasurable! Worse, hardware processing implies hardware resources, so this means that you are limited to the number of hardware voices offered by DirectSound 3D -- typically a very small number on the order of 8 to 16. Also note that no environmental reverb effects are supported when MSS_MC_DIRECTSOUND3D options are selected -- only the EAX options offer reverb effects in hardware. Furthermore, the DirectSound3D multispeaker positioner will work properly only if the end user's speaker configuration is set correctly in the Windows control panel and/or their sound card vendor's proprietary control application. The EAX options add environmental reverb effects to DirectSound 3D, with all of DirectSound3D's accompanying advantages and drawbacks. But hardware acceleration of environmental reverb effects, unlike acceleration of mixing by itself, actually can save CPU time on slower machines. Unfortunately, while EAX is widely emulated in various chipsets (as well as MSS's own software mixer), there is little consistency in reverb levels and quality even among Creative Labs' own products, much less those from other vendors. If consistent reproduction across all platforms is important to your application, don't rely on hardware EAX support -- use the software mixer-based options instead. For all of these reasons, it's better in most cases to skip the DirectSound3D/EAX options in favor of allowing the end user to select the mono, stereo, or MSS_MC_DISCRETE configuration that matches their hardware and let Miles do the mixing and environmental effects internally. Almost all games (and even next-gen console APIs) are moving towards software based sound processing - it's more reliabile, more consistent, and easier to author for. Channel level-control options Regardless of whether a mono, stereo, discrete multichannel, or SRS/Dolby output format is selected, the MSS software mixer gives you a couple of different ways to determine how much sound from a given HSAMPLE reaches each speaker. Obviously, the AIL_set_sample_volume_pan or AIL_set_sample_volume_levels will have the expected effect regardless of the output format. MSS 7, however, has introduced an additional scale factor that affects per-sample volume, the channel level scalar. There's one channel-level scale factor for each combination of source channel (HSAMPLE) and logical channel in the output mix (HDIGDRIVER). MSS multiplies each playing HSAMPLE's 3D/volume/pan-derived level with the channel-level scale factor at each speaker to obtain the volume at that speaker. The maximum level of each source (HSAMPLE/HSTREAM) channel at each output speaker, prior to any volume- or pan-control attenuation, may be set directly by the application via the AIL_set_sample_channel_levels function. Many applications will never need to use AIL_set_sample_channel_levels at all. By default, MSS tries to select a reasonable mapping between source and speaker channels for a given output mode. Rules that establish the default channel-routing behavior include: Note that some aspects of this behavior are different in MSS versions 7.1a and earlier. In these earlier releases, stereo source channels were mapped arbitrarily to successive pairs of output channels, and multichannel HSAMPLEs/HSTREAMs were not supported at all. Another point that must be emphasized is that the behavior described above is only the default. The AIL_set_sample_channel_levels function gives your MSS application complete control over the channel-steering matrices for all of its HSAMPLEs and HSTREAMs... even 3D-positioned ones, if desired! To understand how MSS applies various internally-generated and application-supplied scale factors to HSAMPLE and HSTREAM volume levels, see the Digital Audio Pipeline section. 3D control It's possible for MSS to determine an HSAMPLE's channel levels automatically, by performing distance and directionality calculations based on the relative positions of the HSAMPLE and its HDIGDRIVER (also known as the listener) in 3D space. Positions in 3D space are specified in left-handed coordinates (+X = right, +Y = up, +Z = front) by means of the AIL_set_sample_3D_position and AIL_set_listener_3D_position functions. Once an HSAMPLE has been placed under 3D control, a number of additional MSS API functions can be applied to the HSAMPLE. AIL_set_sample_3D_distances determines how distance-based attenuation is applied to the sound, while the AIL_set_sample_3D_cone and AIL_set_sample_3D_orientation functions give the sound a directional falloff characteristic. AIL_set_sample_3D_velocity applies Doppler shift to the sound. Similar functions apply to the listener object associated with the HDIGDRIVER. When the MSS software mixer is in use, none of the functions whose name contains '_3D_' affect HSAMPLES that have not been assigned a 3D position. Only monaural samples can be meaningfully assigned a 3D position with AIL_set_sample_3D_position. Assigning a 3D position to a stereo sample will result in a forced downmix to mono when that HSAMPLE is processed by the software mixer. Assigning a 3D position to a multichannel sample yields undefined results which may vary from one MSS version to the next. Even after you call AIL_set_sample_3D_position on an HSAMPLE, the sample's channel levels may still be controlled via AIL_set_sample_channel_levels. Any additional channel-level scale factors supplied by the application are simply multiplied with the results of the 3D-positioning algorithm. Note that the only way to disable 3D spatialization of an HSAMPLE is to reinitialize it with a call to AIL_init_sample, AIL_set_sample_info, AIL_set_sample_file, or AIL_set_named_sample_file. You can tell if a given HSAMPLE has been placed under 3D control by examining the return value from AIL_sample_3D_position. Along the same lines, note that discrete control of channel levels is available only with the MSS software mixer; it isn't possible with the DirectSound3D/EAX options. AIL_set_sample_channel_levels and AIL_sample_channel_levels don't work at all on these configurations... and all HSAMPLEs are 3D-positioned, even ones for which you've never called AIL_set_sample_3D_position. So you'll need to open another HDIGDRIVER for 2D-only sounds like menu cues and extradiagetic sound effects, unless every sound effect in your game is 3D-positional. The examms example program demonstrates this principle. Addressing individual speakers MSS's multichannel implementation is based on the master speaker/channel layout plan defined by Microsoft as part of their WDM driver model for Windows 98SE and Windows 2000/XP. In this scheme, up to eighteen channels are specifiable through the use of the MSS_SPEAKER enumeration:
In addition to providing destination-speaker and source-channel index values for use with AIL_set_sample_channel_levels and other functions, this table defines the order in which channels must appear in multichannel source streams. As shown in the table below, only one combination of MSS_SPEAKER output channels is valid for any given number of logical output channels. (As an example, MSS_MC_61_DISCRETE always refers to a speaker configuration consisting of the FL, FR, FC, LFE, BL, BR, and BC output channels.)
Your application doesn't normally need to worry about specific channel-ordering issues because MSS keeps track of which MSS_SPEAKERs are valid for a given HSAMPLE and output driver. And again, this is all moot when using DirectSound3D/EAX, because you don't have any control over individual channel levels to begin with. You can obtain the number of physical and logical channels in use by calling AIL_speaker_configuration, as well as the MSS_MC_SPEC value passed to (or chosen by) AIL_open_digital_driver. As can be seen in the table above, these will be identical for all conventional (non-matrix) discrete formats, while matrix formats such as Dolby and SRS Circle Surround(r) can map three or more logical channels onto two physical channels. DirectSound3D and EAX will report zero physical channels and zero logical channels, since Windows insulates the application from these details. Authoring multichannel content for MSS MSS can play two types of multichannel audio files: Ogg Vorbis files and PCM .WAV files with WAVE_FORMAT_EXTENSIBLE headers. PCM .WAV files can only be played from memory; they cannot be played with AIL_open_stream. Multichannel Ogg Vorbis files, on the other hand, are compatible with all MSS playback functions. Multichannel PCM .WAV file headers have a 32-bit channel mask value whose bits determine which speakers are intended to render the file's source channels. The so-called dwChannelMask value can be passed to AIL_set_sample_info at sample-initialization time via the AILSOUNDINFO structure's channel_mask member, and queried at any time by AIL_sample_channel_count. It should always be 0xFFFFFFFF (~0U) for a standard mono or stereo HSAMPLE. If not all of the mask bits are set, this means that the specified HSAMPLE is a multichannel sample. In this case, the values of the first 18 bits equal 1 if the corresponding MSS_SPEAKER channel is present, or 0 if not. (The LSB, i.e., dwChannelMask & 0x01, corresponds to MSS_SPEAKER_FRONT_LEFT.) The values of subsequent mask bits (bit 18 and beyond) are undefined and should be ignored. Small (< 2 GB total) multichannel PCM .WAV files can be created through the use of the WAVMUX.EXE utility. Using WAVMUX.EXE, it's possible to create a PCM .WAV file that contains gaps in its channel mask. For instance, the command wavmux output.wav none none none none back_left.wav back_right.wav creates a multichannel (WAVE_FORMAT_EXTENSIBLE) .WAV file called output.wav with only its back-left and back-right channels valid. Although this is a two-channel .WAV file, it is not a "stereo" .WAV file, but rather a multichannel .WAV with a dwChannelMask value of 0x0030. Its two channels will be identified as "BL" and "BR" in the Miles Sound Player. Miles fully supports multichannel Ogg Vorbis files. Creating a multichannel Ogg Vorbis file can be as simple as dragging the desired multichannel .WAV file onto an OggDrop window. However, dwChannelMask information from the .WAV source is not preserved in a multichannel Ogg Vorbis file. Instead, the channel layout of an Ogg Vorbis file is inferred from its channel count, according to the following table:
Conventional stereo samples are somewhat faster to process than 2-channel multichannel samples, so MSS assumes that all two-channel Ogg Vorbis files and all standard two-channel .WAV files are stereo samples destined for the front-left/front-right speakers. If you want to perform arbitrary channel steering on a stereo file, you'll need to encode it as a multichannel .WAV file with two valid channels. Working with speaker positions and falloff When MSS opens an HDIGDRIVER in configurations other than DirectSound3D/EAX, it chooses a reasonable set of default positions for the speakers in the configuration. In most cases, the speakers with directional characteristics (i.e., other than the subwoofer/LFE channel) are arrayed at roughly-equal intervals around the unit circle. Sophisticated applications may wish to allow the user to alter MSS's speaker positions to match the positions of the actual speakers that surround the listener. You can call AIL_set_speaker_configuration to submit an array of up to n speaker locations, where n is the number of logical channels in the configuration as reported by AIL_speaker_configuration. The submitted speaker locations will replace the default locations chosen at driver initialization time. Almost all games will want to specify a falloff power greater than 1.0 to exaggerate the movement of sounds between speakers. At 1.0, MSS's 3D pan function is constant in power. A sound will not appear to grow louder or software as it moves around the listener, providing it remains equidistant. Higher falloff powers can make games sound more 'interesting' due to increased apparent movement of sound sources... but this effect comes at the expense of level accuracy, as the sound will not tend to be as loud when it's positioned between speakers. The examms example program can help you judge the effect of different falloff powers. You can use AIL_set_speaker_configuration to change the falloff power without supplying new speaker locations. To do this, simply pass 0 for n_channels and NULL for array. MSS's default falloff power is 3.0. How do stereo HSAMPLEs work in a multi-channel environment? As noted above, stereo samples and streams are mapped to the FR/FL channels in an output mode with >= 2 channels, and combined for output in MSS_MC_MONO mode. In most applications that don't switch between first-person and third-person points of view, it usually doesn't make sense to enable 3D positioning on a stereo sample; the channels will be downmixed to mono at runtime, taking up extra memory space and CPU time. Stereo and multichannel samples don't work at all in DirectSound3D or EAX; you'll need to open a separate HDIGDRIVER to handle them. |
Next Topic (What's the best way to port my older Miles application to MSS 7?)
Previous Topic (How do I play a digital sound?)
Group:
FAQs and How Tos, Overview for Microsoft Xbox, The Digital Audio Pipeline
Related Sections:
Creative's EAX 2 Properties, Creative's EAX 3 Properties, Creative's EAX 4 Properties, Sound under Win32, Sound under Win64
Related Functions:
AIL_WAV_info, AIL_calculate_3D_channel_levels, AIL_init_sample, AIL_open_digital_driver, AIL_open_stream, AIL_quick_startup, AIL_sample_3D_position, AIL_sample_channel_count, AIL_sample_channel_levels, AIL_sample_output_levels, AIL_set_listener_3D_position, AIL_set_named_sample_file, AIL_set_sample_3D_cone, AIL_set_sample_3D_distances, AIL_set_sample_3D_orientation, AIL_set_sample_3D_position, AIL_set_sample_3D_velocity, AIL_set_sample_channel_levels, AIL_set_sample_file, AIL_set_sample_info, AIL_set_sample_volume_levels, AIL_set_sample_volume_pan, AIL_set_speaker_configuration, AIL_set_speaker_reverb_levels, AIL_speaker_configuration, AIL_speaker_reverb_levels
Related Basic Types:
MSS_MC_SPEC, MSS_SPEAKER
Related Structures:
AILSOUNDINFO
Related FAQs:
What's the best way to port my older Miles application to MSS 7?
For technical support, e-mail Miles3@radgametools.com
© Copyright 1991-2007 RAD Game Tools, Inc. All Rights Reserved.